import request from "axios";

import {proxyPath, uploadPath} from '@/config/env';
import {getToken, setToken} from '@/utils/auth'
import website from '@/config/website';
import {signUtil} from '@/utils/sign-util'

export default {
    /**
     * 获取当前登录用户的菜单 (当前接口为路由调用, 后端必须设置不加签)
     * isTop 是否只查询顶部菜单
     * @returns {Promise<*>}
     */
    async getMenus(isTop) {
        let timestamp = new Date().getTime();
        let url = "/api/admin/sys/loginUser/menu/tree"
        let params = {
            disable: 0,
            isTree: true,
            isLoginUser: true,
            root: isTop == null ? null : 1,
        }
        let data = null;
        let sign = signUtil(url, params, data, timestamp)
        let res = await request({
            url: proxyPath + url,
            method: 'get',
            meta: {
                isSerialize: false
            },
            params: params,
            headers: {
                [website.Authorization]: getToken(),
                timestamp: timestamp,
                sign: sign
            }
        });
        return res.data.data;
    }
}
